﻿using guidHelper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MyDapperApi.Models;
using MyDapperApi.Services;
using MyDapperApi.Services.QywxDocument.DigitalizationDemand;
using QYWXUpdate.DataModel;
using QYWXUpdate.DataModel.CheckInfo;
using QYWXUpdate.DataModel.QYWXDocument;

namespace MyDapperApi.Controllers;

[ApiController]
[Route("api/[controller]")]
public class QYWXDocumentController : ControllerBase
{
    private readonly IAutoNetUpdateService _autoNetUpdateService;
    private readonly IDateBaseService _dateBaseService;
    private readonly INetDocumentService _netDocumentService;
    private readonly IDocDigitalizationDemandService _docDigitalizationDemandService;

    public QYWXDocumentController(IAutoNetUpdateService autoNetUpdateService,
        IDateBaseService dateBaseService,
        INetDocumentService netDocumentService,
        IDocDigitalizationDemandService docDigitalizationDemandService)
    {
        _autoNetUpdateService = autoNetUpdateService;
        _dateBaseService = dateBaseService;
        _netDocumentService = netDocumentService;
        _docDigitalizationDemandService = docDigitalizationDemandService;
    }

    //[HttpGet("Test")]
    //public async Task<IActionResult> GetAll()
    //{
    //    var users = await _autoNetUpdateService.AutoUpdateQywxByRole();
    //    return Ok(users);
    //}

    //[HttpGet("TestAdd")]
    //public async Task<IActionResult> TestAdd()
    //{
    //    var entity = new LogMsgEntity()
    //    {
    //        Id = ToolHelper.GUIDTO16(),
    //        Method = "Test",
    //        Class = "Test",
    //        Message = "Test",
    //        Created_On = DateTime.Now,
    //        Type = "Test",
    //    };
    //    var users = await _dateBaseService.AddBaseService(entity);
    //    return Ok(users);
    //}

    [HttpPost("AddDocument")]
    [Authorize]
    public async Task<IActionResult> AddDocument([FromBody] AddDocumentRequest request)
    {
        var users = await _netDocumentService.AddDocument(request);
        return Ok(users);
    }

    [HttpPost("GetDocumentInfo")]
    [Authorize]
    public async Task<IActionResult> GetToken([FromBody] GetDocumentInfoRequest request)
    {
        var users = await _netDocumentService.GetDocumentInfo(request);
        return Ok(users);
    }

    [HttpGet("PagingDocument")]
    [Authorize]
    public async Task<IActionResult> PagingDocument([FromQuery] PagingDocumentRequest request)
    {
        var users = await _netDocumentService.PagingDocument(request);
        return Ok(users);
    }

    [HttpGet("DeleteDocument")]
    [Authorize]
    public async Task<IActionResult> DeleteDocument([FromQuery] IdRequest request)
    {
        var users = await _netDocumentService.DeleteDocument(request);
        return Ok(users);
    }

    [HttpGet("GetDocAuth")]
    [Authorize]
    public async Task<IActionResult> GetDocAuth([FromQuery] IdRequest request)
    {
        var users = await _netDocumentService.GetDocAuthDetail(request);
        return Ok(users);
    }

    [HttpGet("GetTest")]
    public async Task<IActionResult> GetTest()
    {
        var users = await _docDigitalizationDemandService.GetHasFinishedNumber();
        return Ok(users);
    }

    [HttpPost("DeleteAdmin")]
    [Authorize]
    public async Task<IActionResult> DeleteAdmin([FromBody]ChangeDocumentAdminRequest request)
    {
        var users = await _netDocumentService.ChangeAdmin(request,0);
        return Ok(users);
    }

    [HttpPost("AddAdmin")]
    [Authorize]
    public async Task<IActionResult> AddAdmin([FromBody] ChangeDocumentAdminRequest request)
    {
        var users = await _netDocumentService.ChangeAdmin(request,1);
        return Ok(users);
    }
}